import json
import random

def loadCSV(fnm):
    t = ""
    with open(fnm) as f:
        t = f.read()
    t = t.split()

    global dat
    dat = [i.split(",") for i in t]

dat = []
fnm = "fakedata.csv"
loadCSV(fnm)

CLASS = 0
NAME = 1
ID = 2
VOLIN = 3
VOLOUT = 4
VOLLARGE = 5
POSTSCRIPT = 7

ret = {}

def hourToMinute(a):
    return random.randint(0, 10) * 1000

student = []
for i in dat:
    if len(i) == 8:
    	student += [[int(i[ID]), i[NAME], hourToMinute(i[VOLIN]), hourToMinute(i[VOLOUT]), hourToMinute(i[VOLLARGE])]]

ret["student"] = student

thisYear = 2021
# 并且这个应该是指学年而不是当前年份
def classIdToString(a):
	global thisYear
	id = int(a)
	_year = id // 100
	_class = id % 100
	ret = ""
	# 特殊身份的判断
	# 教师 100001 100002
	# 管理员 110001 110002
	# 系统 120003 120004
	if _year//100 == 10:
		ret = "教师"
		return ret
	elif _year//100 == 11:
		ret = "管理员"
		return ret
	elif _year//100 == 12:
		ret = "系统"
		return ret
	
	if _class <= 10:
		ret = ret + "高"
	elif _class <= 17:
		ret = ret + "蛟"
	if _year == thisYear:
		ret = ret + "一"
	elif _year == thisYear - 1:
		ret = ret + "二"
	elif _year == thisYear - 2:
		ret = ret + "三"
	ret = ret + (["NULL","1","2","3","4","5","6","7","8","9","10","NULL","2","3","4","5","6","7"])[_class] #如果我没记错的话校徽是这样的
	ret = ret + "班"

	return ret

classList = [1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17]

user = []
for i in classList:
    user += [[202100 + i, classIdToString(202100 + i), 202100 + i, 1, "e10adc3949ba59abbe56e057f20f883e"]]

for i in classList:
    user += [[202000 + i, classIdToString(202000 + i), 202000 + i, 1, "e10adc3949ba59abbe56e057f20f883e"]]

for i in classList:
    user += [[201900 + i, classIdToString(201900 + i), 201900 + i, 1, "e10adc3949ba59abbe56e057f20f883e"]]

for i in range(1, 201): # 教师
    user += [[100000 + i, classIdToString(100000 + i), 0, 2, "e10adc3949ba59abbe56e057f20f883e"]]

# for i in classList: # 教师
#     user += [[100100 + i, classIdToString(100100 + i), 0, 2, "e10adc3949ba59abbe56e057f20f883e"]]

for i in range(1, 21): # 管理员
    user += [[110000 + i, classIdToString(110000 + i), 0, 3, "e10adc3949ba59abbe56e057f20f883e"]]

for i in range(1, 5): # 系统
    user += [[120000 + i, classIdToString(120000 + i), 0, 4, "e10adc3949ba59abbe56e057f20f883e"]]

ret["user"] = user

ret["volunteer"] = []
ret["stu_vol"] = []
ret["class_vol"] = []

def writeToFile(fnm, c):
    with open(fnm, "w") as f:
        f.write(c)

writeToFile("fakedata.zvms", json.dumps(ret))
